/* 获取所有的频道列表 */
import request from '@/utils/request'
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels',
    method: 'get'
  })
}
/* 登录 */
export const loginAPI = (data) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'post',
    data: data
  })
}
/* 频道数据 */
export const userChannelAPI = () => {
  return request({
    url: '/v1_0/channels',
    method: 'get'
  })
}
/* 获取频道相应文章列表 */
export const articlesListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    method: 'get',
    params: {
      channel_id: channelId,
      timestamp: timestamp || (new Date().getTime())
    }
  })
}
// 文章 - 反馈 - 不感兴趣
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    },
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}

// 文章 - 反馈 - 反馈垃圾内容
export const reportArticleAPI = ({ artId, type }) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target: artId,
    type: type,
    remark: '如果你想写, 你可以逻辑页面判断下, 如果点击类型是0, 再给一个弹出框输入框输入其他问题, 传参到这里'
  },
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
  }
})
/* 获取用户选择的所有频道 */
export const getUserChannelAPI = () => {
  return request({
    url: '/v1_0/user/channels',
    method: 'get'
  })
}

// 频道 - 更新覆盖频道
export const updateChannelsAPI = ({ channels }) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels // 用户已选整个频道数组
  },
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
  }
})
// 频道 - 删除用户指定的频道
export const removeTheChannelAPI = ({ channelId }) => request({
  url: `/v1_0/user/channels/${channelId}`,
  method: 'DELETE',
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
  }
})
// 搜索 - 联想菜单
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
/* 获取搜索结果 */
export const searchResultListAPI = ({ page = 1, perPage = 10, q }) => {
  return request({
    url: '/v1_0/search',
    method: 'get',
    params: {
      page,
      per_page: perPage,
      q
    }
  })
}
// 文章 - 详情
export const articleDetailAPI = (artId) => {
  return request({
    // :id是后台规定的参数名
    // 前端要在对应路径位置传值(不要写:)
    url: `/v1_0/articles/${artId}`
  })
}
/* 关注作者 */
export const followedUserAPI = (target) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    },
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 取关作者 */
export const unFollowedUserAPI = (target) => {
  return request({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
// 文章 - 点赞
export const articleLikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: target
    },
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 取消点赞 */
export const articleDisLikeAPI = (target) => {
  return request({
    url: `/v1_0/article/likings/${target}`,
    method: 'DELETE',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 获取评论列表 */
export const commentListAPI = ({ artId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    },
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 评论点赞 */
export const commentLikingAPI = (target) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    },
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 取消点赞 */
export const commentDisLikingAPI = (target) => {
  return request({
    url: `/v1_0/comment/likings/${target}`,
    method: 'delete',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 增加评论 */
export const sendCommentAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'post',
    headers: {
      Authorization: 'Bear ' + localStorage.getItem('geek-itheima')
    },
    data: {
      target: artId,
      content
    }
  })
}
/* 用户基本资料 */
// 用户 - 基本资料
export const userInfoAPI = () => {
  return request({
    url: '/v1_0/user',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 获取用户个人简介信息 */
export const userInfo = () => {
  return request({
    url: '/v1_0/user/profile',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
  })
}
/* 更新用户头像 */
export const updatePhotoAPI = (formObj) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj,
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    }
    // 如果你的请求体内容是表单对象, 浏览器会自动携带请求头Content-Type为multipart/form-data
  })
}
/* 修改用户个人信息 */
export const updateProfileAPI = ({ birthday, userName }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'patch',
    headers: {
      Authorization: 'Bearer ' + localStorage.getItem('geek-itheima')
    },
    data: {
      birthday: birthday,
      name: userName
    }
  })
}
